Accord Software, Inc.

tutorial13/main.c




/*
 * Accord Software, Inc.
 *
 * Tutorial 13
 *
 * Send a union and receive int
 */
#include "union.h"

main(argc, argv)
	int argc;
	char *argv[];
{
	char *prog = argv[0];
	struct primitives p;

	/* int value */

	p.utype = 1;
	p.u.ival = 0x11;
	printf("%s utype = %d\n", prog, printuval(&p));

	/* short value */

	p.utype = 2;
	p.u.sval = 0x22;
	printf("%s utype = %d\n", prog, printuval(&p));

	/* long value */

	p.utype = 3;
	p.u.lval = 0x33;
	printf("%s utype = %d\n", prog, printuval(&p));

	/* string value */

	p.utype = 4;
	p.u.pval = "testing union";
	printf("%s utype = %d\n", prog, printuval(&p));

	/* double value */

	p.utype = 5;
	p.u.dval = 123.456;
	printf("%s utype = %d\n", prog, printuval(&p));
	exit(0);
}

[ Home | Tutorials | union.c | union.h ]
E-Mail:webmaster@accord.com
[P-034] Updated March 14, 1996
Copyright © 1993-1996 Accord Software, Inc. All rights reserved.